//
//  WBMainViewController.swift
//  weibo
//
//  Created by  郭航 on 16/6/23.
//  Copyright © 2016年 郭航. All rights reserved.
//

import UIKit

class WBMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabber = WBTabBar()
        tabber.tabBarDelegate = self
        
        setValue(tabber, forKey: "tabBar")
        
        addChildViewController(VC: WBHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(VC: WBMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(VC: WBDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(VC: WBMineTableViewController(), title: "我的", imageName: "tabbar_profile")
    }
    
    func addChildViewController(VC VC: UIViewController, title: String, imageName: String) -> () {
        VC.title = title
        
        let nav = UINavigationController(rootViewController: VC)
        
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        
        addChildViewController(nav)
    }
}

extension WBMainViewController: WBTabBarDelegate {
    func addButtonClick(tabBar: WBTabBar) {
        let VC = WBPutOutViewController()
        
        let nav = UINavigationController(rootViewController: VC)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}